package com.xuexi.bootstrap.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

import static com.xuexi.bootstrap.BootstrapApplication.verseList5;
import static com.xuexi.bootstrap.BootstrapApplication.verseList7;


/**
 * @Author 小年
 * @Date 2020/04/15
 */
@Controller
@RequestMapping("/poetry")
public class TangPoetryController {

    public static final Logger logger = LoggerFactory.getLogger( TangPoetryController.class );
    public static final String str = "*";


    @RequestMapping("/tangPoetry")
    public  String tangPoetry(){

        return "tangPoetry";
    };


    @RequestMapping("/read5")
    @ResponseBody
    public  Verse5 dBFReader(Verse5 verse5 )  {
                   List<Verse5> verse5List=new ArrayList<>();
                for(Verse5 ver:verseList5){

                    // di 4 hang
                    if(!verse5.getFourSentence1().equals(str) ){
                        if(!verse5.getFourSentence1().equals(ver.getFourSentence1())){
                            continue;
                        }
                    }
                    if(!verse5.getFourSentence2().equals(str) ){
                        if(!verse5.getFourSentence2().equals(ver.getFourSentence2())){
                            continue;
                        }
                    }
                    if(!verse5.getFourSentence3().equals(str) ){
                        if(!verse5.getFourSentence3().equals(ver.getFourSentence3())){
                            continue;
                        }
                    }
                    if(!verse5.getFourSentence4().equals(str) ){
                        if(!verse5.getFourSentence4().equals(ver.getFourSentence4())){
                            continue;
                        }
                    }
                    if(!verse5.getFourSentence5().equals(str) ){
                        if(!verse5.getFourSentence5().equals(ver.getFourSentence5())){
                            continue;
                        }
                    }




                    // di 3 hang
                    if(!verse5.getThreeSentence1().equals(str) ){
                        if(!verse5.getThreeSentence1().equals(ver.getThreeSentence1())){
                            continue;
                        }
                    }
                    if(!verse5.getThreeSentence2().equals(str)){
                        if(!verse5.getThreeSentence2().equals(ver.getThreeSentence2())){
                            continue;
                        }
                    }
                    if(!verse5.getThreeSentence3().equals(str) ){
                        if(!verse5.getThreeSentence3().equals(ver.getThreeSentence3())){
                            continue;
                        }
                    }
                    if(!verse5.getThreeSentence4().equals(str)){
                        if(!verse5.getThreeSentence4().equals(ver.getThreeSentence4())){
                            continue;
                        }
                    }
                    if(!verse5.getThreeSentence5().equals(str) ){
                        if(!verse5.getThreeSentence5().equals(ver.getThreeSentence5())){
                            continue;
                        }
                    }

                    // di 2 hang
                    if(!verse5.getTwoSentence1().equals(str)){
                        if(!verse5.getTwoSentence1().equals(ver.getTwoSentence1())){
                            continue;
                        }
                    }

                    if(!verse5.getTwoSentence2().equals(str) ){
                        if(!verse5.getTwoSentence2().equals(ver.getTwoSentence2())){
                            continue;
                        }
                    }
                    if(!verse5.getTwoSentence3().equals(str) ){
                        if(!verse5.getTwoSentence3().equals(ver.getTwoSentence3())){
                            continue;
                        }
                    }
                    if(!verse5.getTwoSentence4().equals(str) ){
                        if(!verse5.getTwoSentence4().equals(ver.getTwoSentence4())){
                            continue;
                        }
                    }
                    if(!verse5.getTwoSentence5().equals(str) ){
                        if(!verse5.getTwoSentence5().equals(ver.getTwoSentence5())){
                            continue;
                        }
                    }

                    // di 1 hang
                    if(!verse5.getOneSentence1().equals(str) ){
                        if(!verse5.getOneSentence1().equals(ver.getOneSentence1())){
                            continue;
                        }
                    }
                    if(!verse5.getOneSentence2().equals(str)){
                        if(!verse5.getOneSentence2().equals(ver.getOneSentence2())){
                            continue;
                        }
                    }
                    if(!verse5.getOneSentence3().equals(str) ){
                        if(!verse5.getOneSentence3().equals(ver.getOneSentence3())){
                            continue;
                        }
                    }
                    if(!verse5.getOneSentence4().equals(str)){
                        if(!verse5.getOneSentence4().equals(ver.getOneSentence4())){
                            continue;
                        }
                    }
                    if(!verse5.getOneSentence5().equals(str) ){
                        if(!verse5.getOneSentence5().equals(ver.getOneSentence5())){
                            continue;
                        }
                    }

                    verse5List.add(ver);

                }
                if (verse5List.isEmpty()){
                    return new Verse5();
                }else {
                    if (verse5.getCount()>=verse5List.size()){
                        Verse5 dd=     new Verse5();
                        dd.setCount(-1);
                        return dd;
                    }
                    Verse5 cc=   verse5List.get(verse5.getCount());
                    cc.setCount(verse5.getCount());
                    return cc;
                }

    }



    @RequestMapping("/read7")
    @ResponseBody
    public  Verse7 read7(Verse7 verse7)  {
        List<Verse7> verse7s=new ArrayList<>();
        for(Verse7 ver:verseList7){

            // di 4 hang
            if(!verse7.getFourSentence1().equals(str) ){
                if(!verse7.getFourSentence1().equals(ver.getFourSentence1())){
                    continue;
                }
            }
            if(!verse7.getFourSentence2().equals(str) ){
                if(!verse7.getFourSentence2().equals(ver.getFourSentence2())){
                    continue;
                }
            }
            if(!verse7.getFourSentence3().equals(str) ){
                if(!verse7.getFourSentence3().equals(ver.getFourSentence3())){
                    continue;
                }
            }
            if(!verse7.getFourSentence4().equals(str) ){
                if(!verse7.getFourSentence4().equals(ver.getFourSentence4())){
                    continue;
                }
            }
            if(!verse7.getFourSentence5().equals(str) ){
                if(!verse7.getFourSentence5().equals(ver.getFourSentence5())){
                    continue;
                }
            }

            if(!verse7.getFourSentence6().equals(str) ){
                if(!verse7.getFourSentence6().equals(ver.getFourSentence6())){
                    continue;
                }
            }
            if(!verse7.getFourSentence7().equals(str) ){
                if(!verse7.getFourSentence7().equals(ver.getFourSentence7())){
                    continue;
                }
            }


            // di 3 hang
            if(!verse7.getThreeSentence1().equals(str) ){
                if(!verse7.getThreeSentence1().equals(ver.getThreeSentence1())){
                    continue;
                }
            }
            if(!verse7.getThreeSentence2().equals(str)){
                if(!verse7.getThreeSentence2().equals(ver.getThreeSentence2())){
                    continue;
                }
            }
            if(!verse7.getThreeSentence3().equals(str) ){
                if(!verse7.getThreeSentence3().equals(ver.getThreeSentence3())){
                    continue;
                }
            }
            if(!verse7.getThreeSentence4().equals(str)){
                if(!verse7.getThreeSentence4().equals(ver.getThreeSentence4())){
                    continue;
                }
            }
            if(!verse7.getThreeSentence5().equals(str) ){
                if(!verse7.getThreeSentence5().equals(ver.getThreeSentence5())){
                    continue;
                }
            }
            if(!verse7.getThreeSentence6().equals(str) ){
                if(!verse7.getThreeSentence6().equals(ver.getThreeSentence6())){
                    continue;
                }
            }
            if(!verse7.getThreeSentence7().equals(str) ){
                if(!verse7.getThreeSentence7().equals(ver.getThreeSentence7())){
                    continue;
                }
            }

            // di 2 hang
            if(!verse7.getTwoSentence1().equals(str)){
                if(!verse7.getTwoSentence1().equals(ver.getTwoSentence1())){
                    continue;
                }
            }

            if(!verse7.getTwoSentence2().equals(str) ){
                if(!verse7.getTwoSentence2().equals(ver.getTwoSentence2())){
                    continue;
                }
            }
            if(!verse7.getTwoSentence3().equals(str) ){
                if(!verse7.getTwoSentence3().equals(ver.getTwoSentence3())){
                    continue;
                }
            }
            if(!verse7.getTwoSentence4().equals(str) ){
                if(!verse7.getTwoSentence4().equals(ver.getTwoSentence4())){
                    continue;
                }
            }
            if(!verse7.getTwoSentence5().equals(str) ){
                if(!verse7.getTwoSentence5().equals(ver.getTwoSentence5())){
                    continue;
                }
            }
            if(!verse7.getTwoSentence6().equals(str) ){
                if(!verse7.getTwoSentence6().equals(ver.getTwoSentence6())){
                    continue;
                }
            }
            if(!verse7.getTwoSentence7().equals(str) ){
                if(!verse7.getTwoSentence7().equals(ver.getTwoSentence7())){
                    continue;
                }
            }

            // di 1 hang
            if(!verse7.getOneSentence1().equals(str) ){
                if(!verse7.getOneSentence1().equals(ver.getOneSentence1())){
                    continue;
                }
            }
            if(!verse7.getOneSentence2().equals(str)){
                if(!verse7.getOneSentence2().equals(ver.getOneSentence2())){
                    continue;
                }
            }
            if(!verse7.getOneSentence3().equals(str) ){
                if(!verse7.getOneSentence3().equals(ver.getOneSentence3())){
                    continue;
                }
            }
            if(!verse7.getOneSentence4().equals(str)){
                if(!verse7.getOneSentence4().equals(ver.getOneSentence4())){
                    continue;
                }
            }
            if(!verse7.getOneSentence5().equals(str) ){
                if(!verse7.getOneSentence5().equals(ver.getOneSentence5())){
                    continue;
                }
            }

            if(!verse7.getOneSentence6().equals(str) ){
                if(!verse7.getOneSentence6().equals(ver.getOneSentence6())){
                    continue;
                }
            }
            if(!verse7.getOneSentence7().equals(str) ){
                if(!verse7.getOneSentence7().equals(ver.getOneSentence7())){
                    continue;
                }
            }
            verse7s.add(ver);

        }
        if (verse7s.isEmpty()){
            return new Verse7();
        }else {
            if (verse7.getCount()>=verse7s.size()){
                Verse7 dd=     new Verse7();
                dd.setCount(-1);
                return dd;
            }
            Verse7 cc=   verse7s.get(verse7.getCount());
            cc.setCount(verse7.getCount());
            return cc;
        }
    }

}
